package com.fms.gui.templateCreator.components.date.parts;

import com.fms.gui.templateCreator.components.date.ITimeInformer;

public class MinuteHand extends Hand
{
	private TimeAngleCalculator	calc;
	private int minute;
	private ITimeInformer informer;

	public MinuteHand( ITimeInformer _informer, TimeAngleCalculator _calc)
	{
		super(10.0, 100.0);
		this.calc = _calc;
		this.informer = _informer;		
	}
	
	public MinuteHand( ITimeInformer _informer)
	{
		this(_informer, new TimeAngleCalculator());
	}



	public void moveTo(int x, int y)
	{
		double[] newPosition = new double[]{(double)x, (double)y};
		
		int newMinute = calc.getMinute(newPosition);
		
		int difference = 0;
		if(newMinute < 15 && minute > 45)
		{
			difference = newMinute + 60 - minute;			
		}
		else if ( newMinute > 45 && minute < 15)
		{
			difference = -(minute + 60 - newMinute);			
		}
		else
		{
			difference = newMinute - minute;
		}
		
		informer.addMinutes(difference);
		
		minute = informer.getMinute();
	}

	@Override
	protected double getAngle()
	{
		return calc.minuteToAngle(informer.getMinute());
	}
}
